package com.tlb.ejb;

import com.tlb.dto.Sticky;
import java.util.*;
import javax.persistence.*;

public class AuthDAO {
    private static com.tlb.web.Util util = com.tlb.web.Util.getUtil();

    public AuthDAO() {
    }
    
    
    public void recordUserLogin(int posterId, String uuid) {
        
        try {
            EntityManager em = util.getPersistenceFactory().createEntityManager();
            EntityTransaction tx = em.getTransaction();
            tx.begin();
            
             em.createNativeQuery(
                    "insert into activesession (posterid, logindate, gooduntildate, uuid) \n" +
                    "values (:posterId, now(), date_add(now(), interval 1 year), :uuid);"
                    )
                    .setParameter("posterId", posterId)
                    .setParameter("uuid", uuid)
                    .executeUpdate();
            
            tx.commit();
            em.close();
                        
        } catch(Exception e) {
            System.err.println("Error in record user login for posterid: " + posterId + ", uuid: " + uuid);
            e.printStackTrace();
        }        
    }
    
}


